﻿// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");
Console.WriteLine("---- 类型转换 ---");


int a = 5;
byte b = (byte)a;
Console.WriteLine($"a:{a} - b:{b}");

//Nullable<int> nv = new Nullable<int>();
int? nv = null;
if (nv == null)
{
    Console.WriteLine("Null");
}
else
{
    Console.WriteLine("Not Null.");
}
//Console.WriteLine(nv.ToString());

// int na = nv ?? 10;
nv = 100;
int na = nv ?? 10;
Console.WriteLine(na);
string[] str = ["yuzhimin", "zhouhaitao", "sunhao", "fangshilong"];
Console.WriteLine(str);
Console.WriteLine(str.Length);
Console.WriteLine(str.GetHashCode());
Console.WriteLine("是否为固定长度：" + str.IsFixedSize);
Console.WriteLine("是否为只读：" + str.IsReadOnly);
Console.WriteLine("判断数组是否线程安全：" + str.IsSynchronized);







// 自定义数据类型转换
public class Function
{
    public int Value { get; set; }
    public Function(int number)
    {
        Value = number;
    }

    // 隐式转换
    public static implicit operator int(Function f)
    {
        return f.Value;
    }

    // 显式转换
    public static explicit operator Function(int number)
    {
        return new Function(number);
    }
}














